#pragma once
#include "afxcmn.h"

#include "Utils/FastBlockQueue.h"
#include "Business/QueueContext.h"
#include "Business/Policy/SuperOpenBusiness.h"
#include "afxwin.h"
#include "Business/ExchangeNotify.h"
#include "Control/PPTooltip.h"

class ThreadManager;
class SuperOpenBusiness;
class SuperOpenArgument;
struct Command;
// CSuperOpenBusinessDlg dialog

class CSuperOpenBusinessDlg : public CDialog
{
	DECLARE_DYNAMIC(CSuperOpenBusinessDlg)

public:
	CSuperOpenBusinessDlg(ThreadManager& threadManager);   // standard constructor
	virtual ~CSuperOpenBusinessDlg();

// Dialog Data
	enum { IDD = IDD_SUPER_OPEN_BUSINESS_DLG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()
private:
	CListCtrl m_businessList;
	CComboBox m_contractCombo;
	CEdit m_quantityEdit;
	CEdit m_openPriceEdit;
	CEdit m_stopPriceEdit;
	CEdit m_timeIntervalEdit;
	CButton m_autoOffsetCheck;
	CEdit m_offsetPriceEdit;
	CEdit m_offsetQuantityEdit;
	CComboBox m_hourCombo;
	CComboBox m_minuteCombo;
	CComboBox m_secondCombo;
	CEdit m_msEdit;

protected:
	virtual BOOL OnInitDialog();
	virtual BOOL PreTranslateMessage(MSG* pMsg);

protected:
	virtual void OnOK();
	virtual void OnCancel();

protected:
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnBnClickedBtnAdd();
	afx_msg void OnBnClickedBtnModify();
	afx_msg void OnLvnKeydownBusinessList(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedAutoOffsetCheck();
	afx_msg void OnLvnItemchangedBusinessList(NMHDR *pNMHDR, LRESULT *pResult);

private:
	void InitComboData();
	void InitControls(SuperOpenArgument const& argument);

	void InitContractSel(int contract);
 	void InitStartTime(SYSTEMTIME const& startTime);

	void InitComboByIntValue(CComboBox& combo, int value);
	void InitBusinessList();

	bool Validate();
	void UpdateArgument();

	int GetCommandType(WORD key);
	void OnCommand(Command const& cmd);

	SuperOpenBusiness* AddBusiness(SuperOpenArgument const& argument);
	int GetBusinessIndex(SuperOpenBusiness* business) const;

	void InsertBusiness(SuperOpenBusiness* business);
	void UpdateBusiness(int index,SuperOpenArgument const& argument);

	void HandlerShortcuts(int index, WORD key);

	bool IsAutoOffset() const;
	void PushExchangeStatus(ExchangeStatus::FLAG status);
private:
	void PrintMblMarket();

	ThreadManager& m_threadManager;
	FastBlockQueue::FastBlockQueuePtr m_uiQueue;
	QueueContext m_queueContext;

	ContractCodes const& m_contracts;
	SYSTEMTIME m_startTime;
	SuperOpenArgument m_argument;

	std::map<SuperOpenBusiness*,int> m_businessIndexMap;
	
	int m_notifyColumnPosition;
};
